var a1 ="#fUI/UIPVP/MiniMapIcon/star#";
var a2 = "#fUI/StarCityUI.img/GradeInfo/icon_ss/12#";
var a3 = "#fUI/UIWindow3.img/MirrorDungeonIntrude/btIntrude/normal/0#";

//副本开关
var open = true;
var mapID = 253000100
var Mlevel = 255;
var ET = "FLDC";
var Log = "飞龙道场";
var minL = 200;
var maxL = 250;
var CountS = 2;
var minP = 1;
var maxP = 6;



function start() {
    status = -1;
    action(1, 0, 0);
}
function action(mode, type, selection) {
    if (status >= 1 && mode == 0) {
        cm.sendOk("快捷寻找组队按热键“O”赶快加入组队来挑战组队任务吧。");
        cm.dispose();
        return;
    }
    if (mode == 1)
        status++;
    else
        status--;

    if (status == 0) {
        var em = cm.getEventManager(ET);
        var prop = em.getProperty("state");
        if (prop == null || prop.equals("0")) {
            var vipstr = "#g空#k";
        } else {
            var vipstr = "#r有#k";
        }

        if (cm.getPlayer().getClient().getChannel() == 1) {
            if (cm.getPlayer().getMapId() == mapID) { //传送
                cm.sendYesNo("#e<Boss - "+Log+">#n\r\n你现在确定放弃任务,从这里出去?\r\n#L2##b是的,现在就出去#l");

            } else {
                var pqtry = CountS - cm.getPQLog(Log);
		zyms = ""+a2+"#e<Boss - "+Log+">#n"+a2+"\r\n\r\n冒险家，你想和队友一起攻略#b"+Log+"#k吗？\r\n";

                zyms += "\r\n "+a1+"状态："+vipstr+"       "+a1+"资格：#g"+ pqtry+"#k/#d"+CountS+"#k";
                zyms += "\r\n "+a1+"等级：#d"+minL+"+#k     "+a1+"人数：#d"+minP+"+#k";

                zyms += "\r\n\r\n#L1#"+a3+"#l\r\n \r\n";
                cm.sendSimple(zyms);
            }
        } else {
            cm.sendOk("当前副本只能在1频道进行。");
            cm.dispose();
        }

    } else if (status == 1) {
        if (selection == 1) {
            if (cm.getParty() == null) {
                cm.showInstruction("先创建一个队伍吧",128,7);
		cm.dispose();
            } else if (!cm.isLeader()) {
		cm.showInstruction("害怕!还是请队长来吧!",160,7);
		cm.dispose();
            } else if (!cm.allMembersHere()) {
		cm.showInstruction("有队员不在这里。",125,7);
		cm.dispose();
            } else if (!cm.isAllPartyMembersAllowedLevel(""+minL+"", ""+maxL+"")) {
		cm.showInstruction("入场副本需要 #e#bLV."+minL+"#n#k 以上",160,8);
		cm.dispose();
	    } else if (!cm.isAllPartyMembersAllowedPQ(""+Log+"", CountS)) {
		cm.showInstruction("以下队员没有次数：#r#e\r\n\r\n \"" + cm.getNotAllowedPQMemberName(""+Log+"", ""+CountS+"") + "\" #k#n\r\n",130,8);
		cm.dispose();
            } else if (cm.getMap(mapID) != null && cm.getMap(mapID).getCharactersSize() > 0) {
		cm.showInstruction("已经有队伍在进行了。",155,7);
		cm.dispose();
            } else {
		var party = cm.getPlayer().getParty().getMembers();
                var mapId = cm.getMapId();
                var next = true;
                var levelValid = 0;
                var inMap = 0;

                var it = party.iterator();
                while (it.hasNext()) {
                    var cPlayer = it.next();
                    if (cPlayer.getMapid() == mapId) {
                        inMap += 1;
                    }
                }
	if(party.size() < minP || party.size() > maxP || inMap < minP){
                    next = false;
                }
                if (next) {
                    var em = cm.getEventManager(ET);
                    if (em == null || open == false) {
                        cm.sendSimple("配置文件不存在,请联系管理员。");
                    } else {
                        var prop = em.getProperty("state");
                        if (prop == null || prop.equals("0")) {
			    cm.saveLocation("MULUNG_TC");
                            em.startInstance(cm.getParty(), cm.getMap(), Mlevel);
                        } else {
				cm.showInstruction("已经有队伍在进行了。",155,7);
				cm.dispose();
				return;
                        }

			cm.gainMembersPQ(""+Log+"", 1);
			cm.setPartyEventCount(""+Log+"");
                        cm.worldSpouseMessage(0x20,"『"+Log+"』以玩家 "+cm.getChar().getName()+" 为首领的小队开始挑战 ≮简单模式-"+Log+"≯ 。");
                        cm.dispose();
			//cm.changeMusic("Bgm09/TimeAttack");
			cm.openNpc(1540815,17);
                    }
                } else {
			cm.showInstruction("入场副本需要 #e#b"+minP+"#n#k 人以上",160,8);
			cm.dispose();
                }
            }
        } else if (selection == 2) {
		var returnMap = cm.getSavedLocation("MULUNG_TC");
		if (returnMap <= 0) {returnMap = 100000000;}
		cm.warp(returnMap);
		//cm.clearSavedLocation("MULUNG_TC");
		cm.dispose();
        }

    } else if (mode == 0) {
        cm.dispose();
    }
}
